package com.huffmantreecode;

public class Node implements Comparable<Node>{
    Character data; //数据本身
    int weight; //字符出现的次数表示权值
    Node left;
    Node right;

    public Node(Character data, int weight) {
        this.data = data;
        this.weight = weight;
    }


    @Override
    public String toString() {
        return "Node{" +
                "data=" + data +
                ", weight=" + weight +
                '}';
    }

    @Override
    public int compareTo(Node o) {
        //从小到大进行排序
        return this.weight - o.weight;
    }
    //前序遍历
    public void preOrder(){
        System.out.println(this);
        if(this.left != null){
            this.left.preOrder();
        }
        if(this.right != null){
            this.right.preOrder();
        }
    }
}
